#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-07-21 3:07 下午
# @Author  : yangdy
# @File    : 2020-07-21.95.不同的二叉搜索树II
# @Software: PyCharmCE
from typing import List

# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution:
    def generateTrees(self, n: int) -> List[TreeNode]:
        ans = []
        if n <= 0:
            return ans

        def search(l, r):
            if l > r:
                return [None]
            ret = []
            for x in range(l, r+1):
                left = search(l, x-1)
                right = search(x+1, r)
                for li in left:
                    for ri in right:
                        rt = TreeNode(x, li, ri)
                        ret.append(rt)
            return ret

        ans = search(1, n)

        return ans


solve = Solution()

questions = [
    (3,),
    (0,),
    (1,),
]

for qi, q in enumerate(questions):
    print(f'#{qi}:', q)
    ans_ = solve.generateTrees(q[0])
    print(f'ans[{len(ans_)}]:', ans_)

